import pandas as pd
import numpy as np
import plotly.express as px
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.graph_objs as go
#Reading csv file and converting as DataFrame
df=pd.read_csv("C:/Users/shakt/Downloads/honda_car_selling.csv")
df
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 0 | 2019 | 19006 kms | Petrol | Automatic | 9.29 Lakh | Honda City V CVT |
| 1 | 2021 | 11936 kms | Petrol | Automatic | 13.95 Lakh | Honda City ZX CVT |
| 2 | 2018 | 29635 kms | Petrol | Automatic | 9.95 Lakh | Honda City i-VTEC CVT ZX |
| 3 | 2020 | 16163 kms | Petrol | Automatic | 13.26 Lakh | Honda City ZX CVT |
| 4 | 2015 | 105114 kms | Petrol | Manual | 5.68 Lakh | Honda City i VTEC V |
| ... | ... | ... | ... | ... | ... | ... |
| 994 | 2007 | 90000 kms | Petrol | Manual | 1.22 Lakh | Honda Civic 1.8 V MT |
| 995 | 2016 | 31500 kms | Petrol | Manual | 4.25 Lakh | Honda Amaze S i-VTEC |
| 996 | 2017 | 39735 kms | Petrol | Manual | 5.10 Lakh | Honda Amaze S Petrol |
| 997 | 2017 | 36000 kms | Petrol | Manual | 6.10 Lakh | Honda City i VTEC S |
| 998 | 2015 | 35341 kms | Diesel | Manual | 3 Lakh | Honda Amaze S i-Dtech |
999 rows × 6 columns
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 999 entries, 0 to 998 Data columns (total 6 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Year 999 non-null int64 1 kms Driven 999 non-null object 2 Fuel Type 999 non-null object 3 Suspension 999 non-null object 4 Price 999 non-null object 5 Car Model 999 non-null object dtypes: int64(1), object(5) memory usage: 47.0+ KB
#removing char part from kms Driven column value and convert it as int type
df['kms Driven']=df['kms Driven'].str.replace('kms','').astype(int)
df
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 0 | 2019 | 19006 | Petrol | Automatic | 9.29 Lakh | Honda City V CVT |
| 1 | 2021 | 11936 | Petrol | Automatic | 13.95 Lakh | Honda City ZX CVT |
| 2 | 2018 | 29635 | Petrol | Automatic | 9.95 Lakh | Honda City i-VTEC CVT ZX |
| 3 | 2020 | 16163 | Petrol | Automatic | 13.26 Lakh | Honda City ZX CVT |
| 4 | 2015 | 105114 | Petrol | Manual | 5.68 Lakh | Honda City i VTEC V |
| ... | ... | ... | ... | ... | ... | ... |
| 994 | 2007 | 90000 | Petrol | Manual | 1.22 Lakh | Honda Civic 1.8 V MT |
| 995 | 2016 | 31500 | Petrol | Manual | 4.25 Lakh | Honda Amaze S i-VTEC |
| 996 | 2017 | 39735 | Petrol | Manual | 5.10 Lakh | Honda Amaze S Petrol |
| 997 | 2017 | 36000 | Petrol | Manual | 6.10 Lakh | Honda City i VTEC S |
| 998 | 2015 | 35341 | Diesel | Manual | 3 Lakh | Honda Amaze S i-Dtech |
999 rows × 6 columns
#finding the no of duplicated rows of the df
df.duplicated().value_counts()
False 974 True 25 dtype: int64
#viewing df which has all the duplicated rows (all occurances)
df.loc[df.duplicated(keep=False)]
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 221 | 2018 | 43326 | Petrol | Manual | 4.85 Lakh | Honda Amaze E i-VTEC |
| 223 | 2018 | 43326 | Petrol | Manual | 4.85 Lakh | Honda Amaze E i-VTEC |
| 307 | 2017 | 51000 | Petrol | Automatic | 8.99 Lakh | Honda City i-VTEC CVT ZX |
| 326 | 2012 | 48000 | Petrol | Manual | 2.75 Lakh | Honda Brio S MT |
| 419 | 2020 | 60714 | Petrol | Manual | 6.90 Lakh | Honda Amaze S Petrol |
| 515 | 2017 | 51000 | Petrol | Automatic | 8.99 Lakh | Honda City i-VTEC CVT ZX |
| 734 | 2021 | 38352 | Petrol | Manual | 7.85 Lakh | Honda Amaze VX Petrol |
| 735 | 2021 | 38352 | Petrol | Manual | 7.85 Lakh | Honda Amaze VX Petrol |
| 739 | 2020 | 60714 | Petrol | Manual | 6.90 Lakh | Honda Amaze S Petrol |
| 786 | 2012 | 48000 | Petrol | Manual | 2.75 Lakh | Honda Brio S MT |
| 812 | 2008 | 80000 | Petrol | Manual | 2 Lakh | Honda Civic 1.8 V MT |
| 960 | 2016 | 28000 | Petrol | Manual | 4.70 Lakh | Honda Brio 1.2 VX MT |
| 961 | 2017 | 30000 | Petrol | Manual | 4.50 Lakh | Honda Amaze S i-VTEC |
| 962 | 2008 | 80000 | Petrol | Manual | 2 Lakh | Honda Civic 1.8 V MT |
| 963 | 2016 | 35000 | Diesel | Manual | 6.20 Lakh | Honda Jazz 1.5 VX i DTEC |
| 964 | 2008 | 110000 | Petrol | Manual | 1.25 Lakh | Honda Civic 1.8 V MT |
| 965 | 2015 | 37326 | Petrol | Manual | 5 Lakh | Honda Jazz 1.2 S i VTEC |
| 966 | 2018 | 60000 | Diesel | Manual | 9 Lakh | Honda City i-DTEC V |
| 967 | 2007 | 110000 | Petrol | Manual | 4.50 Lakh | Honda CR-V RVi MT |
| 968 | 2016 | 50000 | Petrol | Automatic | 7.80 Lakh | Honda City i VTEC CVT SV |
| 969 | 2006 | 110000 | Petrol | Manual | 1.80 Lakh | Honda City GXi |
| 970 | 2017 | 16665 | Petrol | Automatic | 11.50 Lakh | Honda City i-VTEC CVT VX |
| 971 | 2013 | 110000 | Diesel | Manual | 3.35 Lakh | Honda Amaze EX i-Dtech |
| 972 | 2019 | 47297 | Petrol | Automatic | 15 Lakh | Honda Civic ZX |
| 973 | 2006 | 186719 | Petrol | Manual | 90,000 | Honda City GXi |
| 974 | 2007 | 90000 | Petrol | Manual | 1.22 Lakh | Honda Civic 1.8 V MT |
| 975 | 2016 | 31500 | Petrol | Manual | 4.25 Lakh | Honda Amaze S i-VTEC |
| 976 | 2017 | 39735 | Petrol | Manual | 5.10 Lakh | Honda Amaze S Petrol |
| 977 | 2017 | 36000 | Petrol | Manual | 6.10 Lakh | Honda City i VTEC S |
| 978 | 2015 | 35341 | Diesel | Manual | 3 Lakh | Honda Amaze S i-Dtech |
| 980 | 2016 | 28000 | Petrol | Manual | 4.70 Lakh | Honda Brio 1.2 VX MT |
| 981 | 2017 | 30000 | Petrol | Manual | 4.50 Lakh | Honda Amaze S i-VTEC |
| 982 | 2008 | 80000 | Petrol | Manual | 2 Lakh | Honda Civic 1.8 V MT |
| 983 | 2016 | 35000 | Diesel | Manual | 6.20 Lakh | Honda Jazz 1.5 VX i DTEC |
| 984 | 2008 | 110000 | Petrol | Manual | 1.25 Lakh | Honda Civic 1.8 V MT |
| 985 | 2015 | 37326 | Petrol | Manual | 5 Lakh | Honda Jazz 1.2 S i VTEC |
| 986 | 2018 | 60000 | Diesel | Manual | 9 Lakh | Honda City i-DTEC V |
| 987 | 2007 | 110000 | Petrol | Manual | 4.50 Lakh | Honda CR-V RVi MT |
| 988 | 2016 | 50000 | Petrol | Automatic | 7.80 Lakh | Honda City i VTEC CVT SV |
| 989 | 2006 | 110000 | Petrol | Manual | 1.80 Lakh | Honda City GXi |
| 990 | 2017 | 16665 | Petrol | Automatic | 11.50 Lakh | Honda City i-VTEC CVT VX |
| 991 | 2013 | 110000 | Diesel | Manual | 3.35 Lakh | Honda Amaze EX i-Dtech |
| 992 | 2019 | 47297 | Petrol | Automatic | 15 Lakh | Honda Civic ZX |
| 993 | 2006 | 186719 | Petrol | Manual | 90,000 | Honda City GXi |
| 994 | 2007 | 90000 | Petrol | Manual | 1.22 Lakh | Honda Civic 1.8 V MT |
| 995 | 2016 | 31500 | Petrol | Manual | 4.25 Lakh | Honda Amaze S i-VTEC |
| 996 | 2017 | 39735 | Petrol | Manual | 5.10 Lakh | Honda Amaze S Petrol |
| 997 | 2017 | 36000 | Petrol | Manual | 6.10 Lakh | Honda City i VTEC S |
| 998 | 2015 | 35341 | Diesel | Manual | 3 Lakh | Honda Amaze S i-Dtech |
#removing the duplicates keeping the first occurences as orig
df=df.drop_duplicates(keep='first')
df
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 0 | 2019 | 19006 | Petrol | Automatic | 9.29 Lakh | Honda City V CVT |
| 1 | 2021 | 11936 | Petrol | Automatic | 13.95 Lakh | Honda City ZX CVT |
| 2 | 2018 | 29635 | Petrol | Automatic | 9.95 Lakh | Honda City i-VTEC CVT ZX |
| 3 | 2020 | 16163 | Petrol | Automatic | 13.26 Lakh | Honda City ZX CVT |
| 4 | 2015 | 105114 | Petrol | Manual | 5.68 Lakh | Honda City i VTEC V |
| ... | ... | ... | ... | ... | ... | ... |
| 975 | 2016 | 31500 | Petrol | Manual | 4.25 Lakh | Honda Amaze S i-VTEC |
| 976 | 2017 | 39735 | Petrol | Manual | 5.10 Lakh | Honda Amaze S Petrol |
| 977 | 2017 | 36000 | Petrol | Manual | 6.10 Lakh | Honda City i VTEC S |
| 978 | 2015 | 35341 | Diesel | Manual | 3 Lakh | Honda Amaze S i-Dtech |
| 979 | 2017 | 8602 | Petrol | Manual | 7.25 Lakh | Honda City V MT AVN |
974 rows × 6 columns
# Checking if any null value is there in any column
df.isna().sum()
Year 0 kms Driven 0 Fuel Type 0 Suspension 0 Price 0 Car Model 0 dtype: int64
#To see top10 most common car models with year have come for the sale
df_year_car_model=df.groupby(['Year', 'Car Model']).size().nlargest(10).to_frame().reset_index()
df_year_car_model.columns=['Year','Car Model', 'Count']
df_year_car_model
| Year | Car Model | Count | |
|---|---|---|---|
| 0 | 2009 | Honda City 1.5 S MT | 21 |
| 1 | 2010 | Honda City 1.5 S MT | 19 |
| 2 | 2014 | Honda Amaze S i-Dtech | 16 |
| 3 | 2013 | Honda Brio S MT | 13 |
| 4 | 2014 | Honda City i DTEC SV | 13 |
| 5 | 2017 | Honda City i VTEC V | 13 |
| 6 | 2015 | Honda Amaze S i-Vtech | 11 |
| 7 | 2015 | Honda City i VTEC V | 11 |
| 8 | 2008 | Honda City GXi | 10 |
| 9 | 2014 | Honda City i DTEC VX | 10 |
#Graphical visualization
fig=px.bar(df_year_car_model,x='Year',y='Count',hover_name='Car Model',color='Car Model')
fig.show()
#To see how many number of each car brandas with three different types of fuel
df_fuel=df.groupby(['Fuel Type','Car Model']).size().to_frame().reset_index()
df_fuel.columns=['Fuel Type','Car Model','Count']
df_fuel
| Fuel Type | Car Model | Count | |
|---|---|---|---|
| 0 | CNG | Honda Amaze S Plus i-VTEC | 1 |
| 1 | Diesel | Honda Amaze E Option i-DT | 2 |
| 2 | Diesel | Honda Amaze E i-DTEC | 1 |
| 3 | Diesel | Honda Amaze E i-Dtech | 3 |
| 4 | Diesel | Honda Amaze EX i-Dtech | 4 |
| ... | ... | ... | ... |
| 179 | Petrol | Honda WR-V Edge Edition i | 2 |
| 180 | Petrol | Honda WR-V SV | 1 |
| 181 | Petrol | Honda WR-V VX | 2 |
| 182 | Petrol | Honda WR-V i-VTEC S | 4 |
| 183 | Petrol | Honda WR-V i-VTEC VX | 14 |
184 rows × 3 columns
#Graphical visual
fig=
fig=px.bar(df_fuel,x='Fuel Type',y='Count',
hover_name='Car Model',
color='Car Model',
range_y=[0,1000])
fig.show()
File "C:\Users\shakt\AppData\Local\Temp\ipykernel_31892\376909864.py", line 2 fig= ^ SyntaxError: invalid syntax
df
#To see the Car models under two different types of Suspension with fule type as Petrol
df_petrol = df[df['Fuel Type'] == ' Petrol ']
df_petrol_sus =df_petrol.groupby(['Suspension','Car Model']).size().to_frame().reset_index()
df_petrol_sus.columns=['Suspension','Car Model','Count']
df_petrol_sus
#visualization tells that under each suspension what types of car models and how many number of cars with each model
fig=px.bar(df_petrol_sus,x='Suspension',y='Count',hover_name='Car Model',color='Car Model')
fig.show()
#Finding the top 10 vehicles with the most miles driven when using petrol and Manual suspension
df_petrol_4year=df_petrol.loc[df_petrol['Year'].isin([2023,2022,2021,2020])]
df_petrol_4year_s=df_petrol_4year[df_petrol_4year['Suspension']==' Manual']
df_petrol_4year_s_top10_km=df_petrol_4year_s.sort_values('kms Driven',ascending=False).head(10)
df_petrol_4year_s_top10_km # top10 cars ran for highest km from the year b/w 2020 to 2023 with suspension type as Manual
#Graphical representation
fig=go.Figure(go.Scatter(x=df_petrol_4year_s_top10_km['Car Model'],y=df_petrol_4year_s_top10_km['kms Driven'],mode='text+markers+lines',text=df_petrol_4year_s_top10_km['kms Driven']))
fig.update_layout( xaxis_title='Car Model', yaxis_title='kms Driven')
fig.show()
#Finding the top 10 vehicles with the most miles driven when using petrol and automatic suspension
df_petrol_4year_s_a=df_petrol_4year[df_petrol_4year['Suspension']==' Automatic']
df_petrol_4year_s_a_top10_km=df_petrol_4year_s_a.sort_values('kms Driven',ascending=False).head(10)
df_petrol_4year_s_a_top10_km # top10 cars ran for highest km from the year b/w 2020 to 2023 with suspension type as Automatic
#Graphical representation
fig=go.Figure(go.Scatter(x=df_petrol_4year_s_a_top10_km['Car Model'],y=df_petrol_4year_s_a_top10_km['kms Driven'],mode='text+markers+lines',text=df_petrol_4year_s_a_top10_km['kms Driven']))
fig.update_layout( xaxis_title='Car Model', yaxis_title='kms Driven')
fig.show()
df_diesel = df[df['Fuel Type'] == ' Diesel ']
df_diesel_sus =df_diesel.groupby(['Suspension','Car Model']).size().to_frame().reset_index()
df_diesel_sus.columns=['Suspension','Car Model','Count']
df_diesel_sus.head(10)
#The image explains which car models are under each suspension as well as how many of each type there are, all using deisel fuel.
fig=px.bar(df_diesel_sus,x='Suspension',y='Count',hover_name='Car Model',color='Car Model')
fig.show()
# filtering df with fuel type: Diesel, Suspension: Manual
df_desiel_4year=df_diesel.loc[df_diesel['Year'].isin([2023,2022,2021,2020])]
df_desiel_4year_s=df_desiel_4year[df_desiel_4year['Suspension']==' Manual']
df_desiel_4year_s_top_km=df_desiel_4year_s.sort_values('kms Driven',ascending=False)
df_desiel_4year_s_top_km
# filstering df with fuel type: Diesel, Suspension: Manual
df_desiel_4year=df_diesel.loc[df_diesel['Year'].isin([2023,2022,2021,2020])]
df_desiel_4year_s=df_desiel_4year[df_desiel_4year['Suspension']==' Automatic']
df_desiel_4year_s_top_km=df_desiel_4year_s.sort_values('kms Driven',ascending=False)
df_desiel_4year_s_top_km
#converting the price column with numerical values with lambda apply method
df['Price'] = df['Price'].apply(lambda x: float(x.replace('Lakh', ''))*100000 if x.endswith('Lakh') else float(x.replace(',', '')))
C:\Users\shakt\AppData\Local\Temp\ipykernel_31892\3333681110.py:2: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
#Finding top10 costliest cars
df_top10_price=df.sort_values(by='Price',ascending=False).head(10)
df_top10_price
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 390 | 2019 | 50175 | Diesel | Automatic | 2650000.0 | Honda CR-V Diesel 2WD |
| 189 | 2019 | 33000 | Petrol | Automatic | 2490000.0 | Honda CR-V 2.0 CVT |
| 394 | 2019 | 10745 | Petrol | Automatic | 1754000.0 | Honda Civic VX |
| 469 | 2019 | 18000 | Petrol | Automatic | 1725000.0 | Honda Civic VX BSIV |
| 858 | 2019 | 79000 | Diesel | Manual | 1720000.0 | Honda Civic VX Diesel |
| 222 | 2022 | 1661 | Petrol | Manual | 1600000.0 | Honda City VX MT |
| 398 | 2022 | 5100 | Petrol | Automatic | 1590000.0 | Honda City i-VTEC CVT ZX |
| 15 | 2022 | 5500 | Petrol | Automatic | 1590000.0 | Honda City ZX CVT |
| 400 | 2022 | 3800 | Petrol | Automatic | 1590000.0 | Honda City i-VTEC CVT ZX |
| 36 | 2021 | 5282 | Petrol | Automatic | 1526000.0 | Honda City ZX CVT |
#Graphical representation
fig=px.bar(df_top10_price,x='Car Model',y='Price',hover_name='Year',color='Car Model',text_auto=True)
fig.update_layout(width=800,height=400)
fig.show()
#Finding top10 Cheapest cars
df_top10_price_Cheap=df.sort_values(by='Price',ascending=False).tail(10)
df_top10_price_Cheap
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 652 | 2008 | 114502 | Petrol | Manual | 100000.0 | Honda Civic 1.8 V MT |
| 764 | 2009 | 87163 | Petrol | Manual | 100000.0 | Honda City 1.5 S MT |
| 572 | 2008 | 223000 | Petrol | Manual | 100000.0 | Honda City GXi |
| 637 | 2009 | 78216 | Petrol | Manual | 100000.0 | Honda Jazz Basic |
| 939 | 2008 | 92000 | Petrol | Manual | 95000.0 | Honda City GXi |
| 973 | 2006 | 186719 | Petrol | Manual | 90000.0 | Honda City GXi |
| 802 | 2007 | 120000 | Petrol | Manual | 85000.0 | Honda City VTEC |
| 594 | 2008 | 39460 | Petrol | Manual | 80000.0 | Honda Civic 1.8 S MT |
| 828 | 2005 | 110000 | Petrol | Manual | 60000.0 | Honda City 1.5 GXI |
| 588 | 2003 | 149714 | Petrol | Manual | 45000.0 | Honda City 1.5 GXI |
#Graphical visualization
fig=px.bar(df_top10_price_Cheap,x='Car Model',y='Price',hover_name='Year',color='Car Model',text_auto=True)
fig.update_layout(width=800,height=400)
fig.show()
#top10 costliest cars with fuel type as petrol and suspension type as Automatic
df_petrol_aut=df[(df['Fuel Type']==' Petrol ') & (df['Suspension']==' Automatic')]
df_petrol_aut_top10=df_petrol_aut.sort_values('Price',ascending=False).head(10)
df_petrol_aut_top10
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 189 | 2019 | 33000 | Petrol | Automatic | 2490000.0 | Honda CR-V 2.0 CVT |
| 394 | 2019 | 10745 | Petrol | Automatic | 1754000.0 | Honda Civic VX |
| 469 | 2019 | 18000 | Petrol | Automatic | 1725000.0 | Honda Civic VX BSIV |
| 15 | 2022 | 5500 | Petrol | Automatic | 1590000.0 | Honda City ZX CVT |
| 398 | 2022 | 5100 | Petrol | Automatic | 1590000.0 | Honda City i-VTEC CVT ZX |
| 400 | 2022 | 3800 | Petrol | Automatic | 1590000.0 | Honda City i-VTEC CVT ZX |
| 36 | 2021 | 5282 | Petrol | Automatic | 1526000.0 | Honda City ZX CVT |
| 972 | 2019 | 47297 | Petrol | Automatic | 1500000.0 | Honda Civic ZX |
| 897 | 2019 | 35000 | Petrol | Automatic | 1500000.0 | Honda Civic VX BSIV |
| 694 | 2020 | 5512 | Petrol | Automatic | 1445000.0 | Honda City ZX CVT |
fig=px.histogram(df_petrol_aut_top10,x='Car Model',nbins=10,color='Price',text_auto=True)
fig.update_layout(width=800, height=500)
fig.show()
#top10 Cheapest cars with fuel typ as petrol and suspension type as Automatic
df_petrol_aut=df[(df['Fuel Type']==' Petrol ') & (df['Suspension']==' Automatic')]
df_petrol_aut_top10_ch=df_petrol_aut.sort_values('Price',ascending=False).tail(10)
df_petrol_aut_top10_ch
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 851 | 2009 | 67300 | Petrol | Automatic | 235000.0 | Honda City 1.5 S AT |
| 791 | 2010 | 90000 | Petrol | Automatic | 230000.0 | Honda City V AT |
| 770 | 2007 | 130000 | Petrol | Automatic | 200000.0 | Honda Accord VTi-L (AT) |
| 577 | 2008 | 100000 | Petrol | Automatic | 200000.0 | Honda Civic 1.8 S AT |
| 482 | 2009 | 92034 | Petrol | Automatic | 200000.0 | Honda Civic 1.8 V AT |
| 102 | 2008 | 120054 | Petrol | Automatic | 196000.0 | Honda Civic 1.8 V AT |
| 532 | 2009 | 72000 | Petrol | Automatic | 195000.0 | Honda Civic 1.8 V AT |
| 360 | 2008 | 71000 | Petrol | Automatic | 195000.0 | Honda Civic 1.8 V AT |
| 506 | 2009 | 102816 | Petrol | Automatic | 180000.0 | Honda City 1.5 S AT |
| 383 | 2009 | 107124 | Petrol | Automatic | 175000.0 | Honda City 1.5 V AT |
#visualization
fig=px.histogram(df_petrol_aut_top10_ch,x='Car Model',nbins=10,color='Price',text_auto=True)
fig.update_layout(width=800, height=500)
fig.show()
#top10 costliest cars with fuel type as petrol and suspension type as Manual
df_petrol_man=df[(df['Fuel Type']==' Petrol ') & (df['Suspension']==' Manual')]
df_petrol_man_top10=df_petrol_man.sort_values('Price',ascending=False).head(10)
df_petrol_man_top10
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 222 | 2022 | 1661 | Petrol | Manual | 1600000.0 | Honda City VX MT |
| 397 | 2022 | 5045 | Petrol | Manual | 1450000.0 | Honda City ZX MT |
| 95 | 2022 | 4696 | Petrol | Manual | 1448000.0 | Honda City ZX MT |
| 854 | 2022 | 8700 | Petrol | Manual | 1400000.0 | Honda City ZX MT |
| 451 | 2022 | 16000 | Petrol | Manual | 1400000.0 | Honda City i-VTEC ZX |
| 695 | 2022 | 15500 | Petrol | Manual | 1380000.0 | Honda City ZX MT |
| 736 | 2020 | 12487 | Petrol | Manual | 1345000.0 | Honda City i-VTEC S |
| 16 | 2021 | 1425 | Petrol | Manual | 1325000.0 | Honda City VX MT |
| 48 | 2020 | 20942 | Petrol | Manual | 1296000.0 | Honda City ZX MT |
| 797 | 2020 | 35000 | Petrol | Manual | 1295000.0 | Honda City ZX MT |
fig=px.histogram(df_petrol_man_top10,x='Car Model',nbins=10,color='Price',text_auto=True)
fig.update_layout(width=800, height=500)
fig.show()
#top10 cheapest cars with fuel type as petrol and suspension type as Manual
df_petrol_man=df[(df['Fuel Type']==' Petrol ') & (df['Suspension']==' Manual')]
df_petrol_man_top10_ch=df_petrol_man.sort_values('Price',ascending=False).tail(10)
df_petrol_man_top10_ch
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 764 | 2009 | 87163 | Petrol | Manual | 100000.0 | Honda City 1.5 S MT |
| 652 | 2008 | 114502 | Petrol | Manual | 100000.0 | Honda Civic 1.8 V MT |
| 572 | 2008 | 223000 | Petrol | Manual | 100000.0 | Honda City GXi |
| 637 | 2009 | 78216 | Petrol | Manual | 100000.0 | Honda Jazz Basic |
| 939 | 2008 | 92000 | Petrol | Manual | 95000.0 | Honda City GXi |
| 973 | 2006 | 186719 | Petrol | Manual | 90000.0 | Honda City GXi |
| 802 | 2007 | 120000 | Petrol | Manual | 85000.0 | Honda City VTEC |
| 594 | 2008 | 39460 | Petrol | Manual | 80000.0 | Honda Civic 1.8 S MT |
| 828 | 2005 | 110000 | Petrol | Manual | 60000.0 | Honda City 1.5 GXI |
| 588 | 2003 | 149714 | Petrol | Manual | 45000.0 | Honda City 1.5 GXI |
fig=px.histogram(df_petrol_man_top10_ch,x='Car Model',nbins=10,color='Price',text_auto=True)
fig.update_layout(width=800, height=500)
fig.show()
#To see the df which has fuel type as Diesel and Suspension type as Automatic
#This df has totally 5 cars
df_diesel_aut=df[(df['Fuel Type']==' Diesel ') & (df['Suspension']==' Automatic')]
df_diesel_aut
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 38 | 2019 | 68816 | Diesel | Automatic | 795000.0 | Honda Amaze V CVT Diesel |
| 390 | 2019 | 50175 | Diesel | Automatic | 2650000.0 | Honda CR-V Diesel 2WD |
| 505 | 2018 | 50000 | Diesel | Automatic | 730000.0 | Honda Amaze S CVT Diesel |
| 761 | 2018 | 53955 | Diesel | Automatic | 675000.0 | Honda Amaze V CVT Diesel |
| 917 | 2021 | 30000 | Diesel | Automatic | 1150000.0 | Honda Amaze VX CVT Diesel |
#top10 costliest cars with fuel typ as Diesel and suspension type as Manual
df_diesel_aut=df[(df['Fuel Type']==' Diesel ') & (df['Suspension']==' Manual')]
df_diesel_man_top10=df_diesel_aut.sort_values('Price',ascending=False).head(10)
df_diesel_man_top10
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 858 | 2019 | 79000 | Diesel | Manual | 1720000.0 | Honda Civic VX Diesel |
| 714 | 2019 | 23561 | Diesel | Manual | 1100000.0 | Honda BR-V i-DTEC V MT |
| 840 | 2019 | 40000 | Diesel | Manual | 1090000.0 | Honda City i-DTEC VX |
| 929 | 2019 | 80000 | Diesel | Manual | 1010000.0 | Honda WR-V i-DTEC VX |
| 952 | 2021 | 70000 | Diesel | Manual | 1000000.0 | Honda WR-V VX Diesel |
| 325 | 2019 | 54000 | Diesel | Manual | 990000.0 | Honda City i-DTEC VX |
| 738 | 2017 | 31000 | Diesel | Manual | 975000.0 | Honda City i-DTEC ZX |
| 228 | 2020 | 33174 | Diesel | Manual | 920000.0 | Honda WR-V i-DTEC VX |
| 941 | 2019 | 110000 | Diesel | Manual | 915000.0 | Honda WR-V i-DTEC VX |
| 966 | 2018 | 60000 | Diesel | Manual | 900000.0 | Honda City i-DTEC V |
#Graphical representation
fig=px.histogram(df_diesel_man_top10,x='Car Model',nbins=10,color='Price',text_auto=True)
fig.update_layout(width=800, height=500)
fig.show()
#top10 cheapest cars with fuel typ as Diesel and suspension type as Manual
df_diesel_man_top10_ch=df_diesel_aut.sort_values('Price',ascending=False).tail(10)
df_diesel_man_top10_ch
| Year | kms Driven | Fuel Type | Suspension | Price | Car Model | |
|---|---|---|---|---|---|---|
| 492 | 2013 | 88000 | Diesel | Manual | 250000.0 | Honda Amaze S i-Dtech |
| 585 | 2014 | 125690 | Diesel | Manual | 245000.0 | Honda Amaze S i-Dtech |
| 806 | 2014 | 91332 | Diesel | Manual | 230000.0 | Honda Amaze S i-Dtech |
| 921 | 2013 | 110000 | Diesel | Manual | 230000.0 | Honda Amaze EX i-Dtech |
| 554 | 2014 | 66776 | Diesel | Manual | 230000.0 | Honda Amaze S i-Dtech |
| 571 | 2014 | 205546 | Diesel | Manual | 225000.0 | Honda Mobilio V i-DTEC |
| 576 | 2015 | 95338 | Diesel | Manual | 225000.0 | Honda Amaze S i-Dtech |
| 380 | 2013 | 114565 | Diesel | Manual | 212000.0 | Honda Amaze S i-Dtech |
| 634 | 2014 | 79303 | Diesel | Manual | 200000.0 | Honda Amaze EX i-Dtech |
| 229 | 2013 | 110000 | Diesel | Manual | 200000.0 | Honda Amaze E i-Dtech |
#Graphical representation
fig=px.histogram(df_diesel_man_top10_ch,x='Car Model',nbins=10,color='Price',text_auto=True)
fig.update_layout(width=800, height=500)
fig.show()
#Finding correlation among the numerical columns
corr=df.corr()
corr
| Year | kms Driven | Price | |
|---|---|---|---|
| Year | 1.000000 | -0.366504 | 0.766076 |
| kms Driven | -0.366504 | 1.000000 | -0.309837 |
| Price | 0.766076 | -0.309837 | 1.000000 |
#creating heatmap to have clear identification of the relationship
fig=plt.figure(figsize=(8,6),dpi=100)
sns.heatmap(data=corr,annot=True, cmap='rocket')
<AxesSubplot:>
#finding:
# Year and price have positive relationship =>year increases, the price is also increasing
#kms Driven and price have negative relationship= KMS increases , the price gets descresing